package es.xpt.ysf.utils;

import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.naming.Context;

public class DefaultJndiProperties {
	 private static final String JNDI_FACTORY = "org.jboss.security.jndi.JndiLoginInitialContextFactory";
	 
	 public static Properties getJndiProperties() {
		 Properties prop = new Properties();   
		 prop.put( Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY );
		 return prop;
	 }
	 	 
	 public static Properties loadCustomJndiProperties(){ // NO_UCD
		  Properties result = null;
		  try {
			  ResourceBundle bundle = ResourceBundle.getBundle("custom_jndi");
			  result = new Properties();
			  String key = null;
			  for (Enumeration<String> e = bundle.getKeys(); e.hasMoreElements();) {
				  key = e.nextElement();
				  result.put(key, bundle.getString(key));
			  }
		  } catch(MissingResourceException mre) {
			  // No existe el fichero -> se devuelve null.
		  }
		  return result;
		}
}
